package SA.teacher.notice;

import java.util.ArrayList;
import SA.teacher.R;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class NoticeAdapter extends BaseAdapter {

	private Context context;
	private ArrayList<NoticeData> arrData1;
	private LayoutInflater inflater;
	String id;


	public NoticeAdapter(Context c, ArrayList<NoticeData> arr,String id) {
		
		this.id = id;
		this.context = c;
		this.arrData1 = arr;
		inflater = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}

	public int getCount() {
		return arrData1.size();
	}

	public String getItem(int position) {
		return arrData1.get(position).getPostTitle();
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(final int position, View convertView, ViewGroup parent) {

		if (convertView == null) {
			convertView = inflater.inflate(R.layout.notice1_list, parent, false);
		}

		TextView postNum = (TextView) convertView.findViewById(R.id.nNumber);
		postNum.setText(arrData1.get(position).getPostNum());

		TextView postTitle = (TextView) convertView.findViewById(R.id.nTitle);
		postTitle.setText(arrData1.get(position).getPostTitle());
		postTitle.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				Intent intent = new Intent(context, NoticeView2.class);

				intent.putExtra("ID",id);
				context.startActivity(intent);
			}});

		TextView postDate = (TextView) convertView.findViewById(R.id.nDate);
		postDate.setText(arrData1.get(position).getPostDate());


		return convertView;
	}

}
